﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StockTransferList.aspx.cs"
    Inherits="SalesManagement.Modules.Warehouse.StockTransferList" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Danh sách phiếu chuyển kho</title>

    <script src="../../Javascript/Global.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
        function DocumentReady() {
            var obj = document.getElementById('ResourceManager1');
            MethodNamespace.DocumentReady({
                success: function() {
                    stVoucherList.reload();
                }
            });
        }
        /*
        Khi chọn Phiếu Nhập kho load chi tiết phiếu nhập
        */
        function SelectionChange(Selection) {
            if (Selection.selections.items.length > 0) {
                var Row = Selection.selections.items[0];
                MethodNamespace.SelectionChange(Row.data.VoucherId);
            }
        }

        function SearchDocument() {
            MethodNamespace.SearchDocument(1, {
                success: function() {
                    Complete_Search(grVoucherList, null, null, txtVoucherNo);
                }
            });
        }
        function DeleteProcess() {
            vnMessageBoxConfirm('Xóa Phiếu chuyển kho', 'Bạn có muốn xóa không?', Ext.MessageBox.OKCANCEL, 'DeleteVoucher()', '', Ext.MessageBox.QUESTION, 1);
        }
        function DeleteVoucher() {
            var items = grVoucherList.selModel.selections.items[0];
            if (items.id != null || items.id != "") {
                MethodNamespace.DeleteProcess(items.id, {
                    success: function(resul) {
                        if (resul) {
                            var RecoIndext = grVoucherList.store.indexOfId(items.id);
                            grVoucherList.deleteSelected();
                            grVoucherList.store.commitChanges();
                            grVoucherDetail.removeAll();
                            if (grVoucherList.store.data.length == 0)
                                SearchDocument();
                            else {
                                if (RecoIndext >= grVoucherList.store.data.length)
                                    RecoIndext = grVoucherList.store.data.length - 1;
                                Complete_Search(grVoucherList, RecoIndext, null, txtVoucherNo);
                            }
                            vnMessageBox('Thông báo !', 'Xóa thành công', Ext.MessageBox.OK, 'Complete_Search(grVoucherList, null, null, txtVoucherNo);', Ext.MessageBox.INFO, 1);
                        }
                    }
                });
            }
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="MethodNamespace">
        <Listeners>
            <DocumentReady Handler="DocumentReady();" Delay="100" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="storeWarehouse" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="WarehouseId">
                <Fields>
                    <ext:RecordField Name="WarehouseId" />
                    <ext:RecordField Name="WarehouseName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="storeEmployee" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="EmployeeId">
                <Fields>
                    <ext:RecordField Name="EmployeeId" />
                    <ext:RecordField Name="EmployeeName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="ViewPort1" runat="server" Layout="RowLayout">
        <Items>
            <ext:Toolbar ID="tbMain" runat="server">
                <Items>
                    <ext:ToolbarSpacer />
                    <ext:Button ID="btnAdd" runat="server" Text="Thêm mới" Icon="FolderAdd">
                        <DirectEvents>
                            <Click OnEvent="btnAdd_Click" />
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button ID="btnEdit" runat="server" Text="Hiệu chỉnh" Icon="FolderEdit">
                        <DirectEvents>
                            <Click OnEvent="btnEdit_Click" />
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button ID="btnDelete" runat="server" Text="Xóa" Icon="FolderDelete">
                        <Listeners>
                            <Click Handler="DeleteProcess()" />
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Toolbar>
            <ext:Panel ID="Panel0" runat="server" Frame="true" Height="100" Layout="ColumnLayout"
                Border="false">
                <Defaults>
                    <ext:Parameter Name="Anchor" Value="99%">
                    </ext:Parameter>
                </Defaults>
                <Items>
                    <ext:Panel ID="Panel1" runat="server" ColumnWidth="0.5" Layout="FormLayout" LabelWidth="100"
                        Border="true">
                        <Defaults>
                            <ext:Parameter Name="Anchor" Value="99%">
                            </ext:Parameter>
                        </Defaults>
                        <Items>
                            <ext:TextField ID="txtVoucherNo" runat="server" FieldLabel="Số phiếu" Editable="false"
                                DataIndex="Title" />
                            <ext:DateField ID="txtToDate" runat="server" FieldLabel="Từ ngày" Format="d/m/Y" />
                            <ext:ComboBox ID="cboWarehouse" runat="server" FieldLabel="Kho chuyển" Editable="false"
                                AllowBlank="true" DataIndex="Title" StoreID="storeWarehouse" DisplayField="WarehouseName"
                                ValueField="WarehouseId" SelectedIndex="0" EmptyText="Tất cả" />
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="Panel3" runat="server" ColumnWidth="0.4" Layout="FormLayout" LabelWidth="70"
                        Border="false">
                        <Defaults>
                            <ext:Parameter Name="Anchor" Value="99%">
                            </ext:Parameter>
                        </Defaults>
                        <Items>
                            <ext:ComboBox ID="cboEmployee" runat="server" FieldLabel="Nhân viên" Editable="false"
                                AllowBlank="true" DataIndex="Title" StoreID="storeEmployee" DisplayField="EmployeeName"
                                ValueField="EmployeeId" SelectedIndex="0" EmptyText="Tất cả" />
                            <ext:DateField ID="txtFromDate" runat="server" Width="200" FieldLabel="Đến ngày"
                                Format="d/m/Y" />
                            <ext:ComboBox ID="cboToWarehouse" runat="server" FieldLabel="Kho đích" Editable="false"
                                AllowBlank="true" DataIndex="Title" StoreID="storeWarehouse" DisplayField="WarehouseName"
                                ValueField="WarehouseId" SelectedIndex="0" EmptyText="Tất cả" />
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="pnlPackCenter" runat="server" Layout="VBoxLayout" ColumnWidth="0.1"
                        Border="true">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 0 5 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:VBoxLayoutConfig Padding="5" Align="Center" Pack="Center" />
                        </LayoutConfig>
                        <Items>
                            <ext:Button ID="btSearch" runat="server" Text="Tìm kiếm" Icon="Magnifier" FormBind="true"
                                Width="60" Height="30">
                                <Listeners>
                                    <Click Handler="stVoucherList.reload()" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Panel>
            <ext:GridPanel ID="grVoucherList" runat="server" AutoExpandColumn="Note" RowHeight="1"
                Border="false">
                <Store>
                    <ext:Store ID="stVoucherList" runat="server" OnRefreshData="VoucherList_OnRefreshData"
                        AutoLoad="true" RemotePaging="true">
                        <Reader>
                            <ext:JsonReader IDProperty="VoucherId">
                                <Fields>
                                    <ext:RecordField Name="VoucherId" />
                                    <ext:RecordField Name="VoucherNo" />
                                    <ext:RecordField Name="VocherDate" />
                                    <ext:RecordField Name="WarehouseId" />
                                    <ext:RecordField Name="ToWarehouseId" />
                                    <ext:RecordField Name="WarehouseName" />
                                    <ext:RecordField Name="ToWarehouseName" />
                                    <ext:RecordField Name="Note" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <BaseParams>
                            <ext:Parameter Name="start" Value="0" Mode="Raw" />
                            <ext:Parameter Name="limit" Value="50" Mode="Raw" />
                        </BaseParams>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="VoucherNo" DataIndex="VoucherNo" Header="Số phiếu" Width="150" />
                        <ext:DateColumn DataIndex="VocherDate" Header="Ngày tạo" Format="dd/MM/yyyy" />
                        <ext:Column DataIndex="WarehouseName" Header="Kho chuyển" Width="200" />
                        <ext:Column DataIndex="ToWarehouseName" Header="Kho đích" Width="200" />
                        <ext:Column DataIndex="Note" Header="Ghi chú" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel SingleSelect="true">
                        <Listeners>
                            <SelectionChange Fn="SelectionChange" />
                        </Listeners>
                    </ext:RowSelectionModel>
                </SelectionModel>
                <BottomBar>
                    <ext:PagingToolbar runat="server" PageSize="50" DisplayInfo="true" DisplayMsg="Đang xem dòng {0} đến {1} của {2}"
                        EmptyMsg="Không có dữ liệu" />
                </BottomBar>
                <LoadMask ShowMask="true" />
            </ext:GridPanel>
            <ext:GridPanel ID="grVoucherDetail" runat="server" AutoExpandColumn="ProductName"
                Border="false" Height="170">
                <Store>
                    <ext:Store ID="stVoucherDetail" runat="server">
                        <Reader>
                            <ext:JsonReader IDProperty="ProductId">
                                <Fields>
                                    <ext:RecordField Name="ProductCode" />
                                    <ext:RecordField Name="ProductName" />
                                    <ext:RecordField Name="UnitName" />
                                    <ext:RecordField Name="Quantity" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel2" runat="server">
                    <Columns>
                        <ext:Column ColumnID="ProductCode" DataIndex="ProductCode" Header="Mã hàng" />
                        <ext:Column DataIndex="ProductName" Header="Tên hàng" />
                        <ext:Column DataIndex="UnitName" Header="Đơn vị tính" />
                        <ext:Column DataIndex="Quantity" Header="Số lượng" />
                    </Columns>
                </ColumnModel>
                <LoadMask ShowMask="true" />
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
